﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    enum MachineName
    {
        刘备 = 1,
        孙权,
        曹操
    }

    class Program
    {

        static void Main(string[] args)

        {
            Console.WriteLine("-------------------欢迎进入游戏世界！---------------------");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("==========================================================");
            Console.WriteLine("=====================猜拳！开始！=========================");
            Console.WriteLine("==========================================================");

            Console.WriteLine("出拳规则：1.石头 2.剪刀 3.布");
            Console.WriteLine();

            Console.WriteLine("请输入您的姓名：");
            string playName = Console.ReadLine();
            Console.WriteLine("请选择对方角色 <1.刘备 2.孙权 3.曹操>");
            int choose1 = int.Parse(Console.ReadLine());
            MachineName f = (MachineName)choose1;
            Machine machine = new Machine(f.ToString());

            Player player = new Player(playName);
            Console.WriteLine("{0} vs {1} 对战 ！", playName, f);
            Console.WriteLine("开始游戏吗？（y/n）");
            string YN = Console.ReadLine();


            if (YN.Equals("y"))
            {

                int choose = player.punch();
                int num = machine.punch();
                int score=0;
                int scoreM = 0;
                int count=0;
                judge(choose, num,ref score ,ref scoreM,ref count);
                next(choose, num, player, machine,playName,f,score,count,scoreM);
                Console.WriteLine();
                Console.WriteLine("============================================");
                Console.WriteLine("{0} vs {1} 对战 ！", playName, f);
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("游戏已关闭！");
            }

        }

        private static void next(int choose, int num, Player player, Machine machine,string playName, MachineName f,int score,int count, int scoreM)
        {
            while (true)
            {

                Console.WriteLine("是否要进行下一轮（y/n）");
                string YN2 = Console.ReadLine();
                if (YN2.Equals("y"))
                {
                    choose = player.punch();
                    num = machine.punch();
                    judge(choose, num,ref  score ,ref  count,ref scoreM);              
                }
                else
                {
                    Console.WriteLine("============================================");
                    Console.WriteLine("{0} vs {1} 对战 ！", playName, f);
                    Console.WriteLine("对战次数{0}",count);
                    Console.WriteLine();
                    Console.WriteLine("姓名               得分");
                    Console.WriteLine("{0}               {1}",playName, score);
                    Console.WriteLine("{0}               {1}",f, scoreM);
                    if (score>scoreM)
                    {
                        Console.WriteLine("{0}赢，{1}笨蛋", playName, f);
                    }
                    if (score < scoreM)
                    {
                        Console.WriteLine("{0}赢，{1}笨蛋", f,playName);
                    }
                    if (score < scoreM)
                    {
                        Console.WriteLine("居然是平局！！！");
                    }
                    // Console.WriteLine("要进行下一局吗（y/n）");
                    next(choose, num, player, machine, playName, f, score, count, scoreM);
                    break;
                }
            }
        }

        private static int judge(int choose, int num, ref int score, ref int count, ref int scoreM)
        {
            
            
            if (choose == 1 && num == 2 || choose == 2 && num == 3 || choose == 3 && num == 1)
            {
                Console.WriteLine("恭喜您，获胜了！");
                score++;
                count++;
            }
            if (choose == 1 && num == 1 || choose == 2 && num == 2 || choose == 3 && num == 3)
            {
                Console.WriteLine("真可惜，平局！");
                count++;
            }
            if (choose == 2 && num == 1 || choose == 3 && num == 2 || choose == 1 && num == 3)
            {
                Console.WriteLine("哎哎哎，您输了！");
                scoreM++;
                count++;
            }
            return score;
        }
    }
}
